package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.User;
import com.fs.pojo.UserInfo;
import com.fs.service.UserInfoService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.PageBean;
import com.fs.vo.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Version:1.0
 * @Description: TODO(一句话描述该类的功能)
 * @Date: 2024/9/25 20:25
 * @Author: love you qxl
 */
@RestController
public class UserInfoController {
    @Resource
    private UserInfoService userInfoService;

    public void setUserInfoService(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    @RequestMapping("/queryAll")
//    @CrossOrigin
    public ResponseData queryAll(){
        List<UserInfo> users = userInfoService.queryAll();
        return ResponseDataUtil.buildOk(users);
    }

    @GetMapping("/query/{currentPage}/{pageSize}")
//    @CrossOrigin
    public ResponseData<Page<UserInfo>> getPages(@PathVariable int currentPage,@PathVariable int pageSize){
        System.out.println(currentPage+":"+pageSize);
        Page<UserInfo> page = userInfoService.getPage(currentPage, pageSize);
        return ResponseDataUtil.buildOk(page);
    }

    @RequestMapping("/add")
    @CrossOrigin
    public ResponseData add(@RequestBody UserInfo userInfo){
        boolean add = userInfoService.add(userInfo);
        return ResponseDataUtil.buildOk(add);
    }

    @RequestMapping("/queryById/{id}")
//    @CrossOrigin
    public ResponseData queryById(@PathVariable Integer id){
        UserInfo userInfo = userInfoService.queryById(id);
        return ResponseDataUtil.buildOk(userInfo);
    }

    @RequestMapping("/update")
//    @CrossOrigin
    public ResponseData update(@RequestBody UserInfo userInfo){
        boolean update = userInfoService.update(userInfo);
        return ResponseDataUtil.buildOk(update);
    }

    @DeleteMapping("/delete/{id}")
//    @CrossOrigin
    public ResponseData delete(@PathVariable Integer id){
        boolean delete = userInfoService.delete(id);
        return ResponseDataUtil.buildOk(delete);
    }


}
